<?php
	header("Content-Type: text/html;charset=utf-8");
	include("function/_nosql.php"); //
	include("function/function.php");
	$action = chkstr(trim($_REQUEST['action']));
	$user_phone = chkstr(trim($_REQUEST['user_phone']));
	$user_phonecode = chkstr(trim($_REQUEST['user_phonecode']));
	$user_password = chkstr(trim($_REQUEST['user_password']));
	$user_repassword = chkstr(trim($_REQUEST['user_repassword']));
	if($action == "save"){
		// 手机号验证
		if(!isMobile($user_phone)){
			echo erro("手机号格式错误！");
		}
	
		// 验证码验证
		if(strlen($user_phonecode)<1){
			echo erro("请正确输入验证码！");
		}
		if($user_phone != $_SESSION['PhoneName']){
			echo erro("请正确输入手机号！");
		}
		if($user_phonecode != $_SESSION['PhoneCode']){
			echo erro("请正确输入验证码！");
		}
	
	
		// 密码验证
		if(strlen($user_password)<5){
			echo erro("密码不能少于5位字符！");
		}
		if(strlen($user_repassword)<5){
			echo erro("两次密码输入不一致！");
		}
		if($user_password != $user_repassword){
			echo erro("两次密码输入不一致！");
		}
		
		$is_reguser = getNewsNums("kboy_user","user_phone='$user_phone'");
		if($is_reguser<1){
			echo erro("该用户不存在！");
		}
		$user_password = md5(md5($user_password));
		// 修改数据
		$mysql = new sqlstr("kboy_user"); 
		$mysql -> set("user_password",$user_password);
		$news_sql = $mysql -> updateSql("user_phone='$user_phone'");
		$news_res = mysql_query($news_sql);
		if($news_res){
			$_SESSION['PhoneName'] = "";
			$_SESSION['PhoneCode'] = "";
			$_SERVER['HTTP_REFERER'] = "";
			echo ok("操作成功","user_index.php");
		}else{
			echo erro("服务器内部错误");
		}
	}else{
		echo erro("参数错误");
	}
	
?>